#ifndef HDCAMERACALIBRATION_H
#define HDCAMERACALIBRATION_H

#include <QThread>
#include "hdshareddata.h"

class HDCameraCalibration : public QThread
{
	Q_OBJECT

public:
	HDCameraCalibration(QObject *parent);
	~HDCameraCalibration();

	bool isCalibrationFinished();
	bool SaveRectificationMaps(char* pathCamZeroX,char* pathCamZeroY, char* pathCamOneX, char* pathCamOneY, char* pathMatUnprojection);
	bool LoadRectificationMaps(char* pathCamZeroX,char* pathCamZeroY, char* pathCamOneX, char* pathCamOneY, char* pathMatUnprojection);

signals:
	void PreparingImagesProgress(int percentDone);
	void CalibrationStarted();
	void CalibrationFinished();

protected:
	void run();

private:
	void PreparingImages();
	void RectifyingImages();
	void Calibrating();
	void InitObjectPoints();

	CvMat* _ObjectPoints;
	CvMat* _ZeroImagesPoints;
	CvMat* _OneImagesPoints;
	CvMat* _PointCounts;

	CvMat** _arrCamera_Intrinsic;
	CvMat** _arrCamera_Distortion;
	CvMat** _UndistortMapX;
	CvMat** _UndistortMapY;
	CvMat** _RectifyMapX;
	CvMat** _RectifyMapY;

	CvMat* _matCalibtationR;
	CvMat* _matCalibrationT;
	CvMat* _matCalibrationF;
	CvMat* _matCalibrationE;


	float _fEtalonUnit;
	CvSize _CheckboardSize;

	bool _bUndistortionPossible;
	int _iCapturedFrames;

};

#endif // HDCAMERACALIBRATION_H
